//package com.fdb.efp.limit.service.impl;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.Objects;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.stereotype.Service;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONObject;
//import com.fdb.efp.console.service.facade.PubSysInfoService;
//import com.fdb.efp.ctr.service.facade.CtrLoanContService;
//import com.fdb.basic.framework.core.base.FrameworkService;
//import com.fdb.basic.framework.core.constant.BaseConstant;
//import com.fdb.basic.framework.core.constant.ESBConstant;
//import com.fdb.basic.framework.core.exception.PauseException;
//import com.fdb.basic.framework.core.util.StringUtil;
//import com.fdb.basic.framework.core.util.TimeUtil;
//import LimitConstant;
//import LmtAdjustAppDao;
//import LmtFreezeAppDao;
//import LmtIndivAppDao;
//import LmtPrdContDao;
//import LmtPrelistDao;
//import LmtShowInfoDao;
//import LmtTerminateAppDao;
//import LmtAdjustApp;
//import LmtIndivApp;
//import LmtPrdCont;
//import LmtPrelist;
//import LmtShowInfo;
//import LmtTerminateApp;
//import com.fdb.efp.limit.service.facade.LmtAdjustAppService;
//import LmtAdjustAppVO;
//import LmtPrdContVO;
//import PreCreStatus;
//
///**
// * <p>
// * 额度调整申请表的Service实现类
// * </p>
// * @author szbd
// * @createDate 2018-09-18 17:36:42
// */
//@Service("lmtAdjustAppService")
//public class LmtAdjustAppServiceImpl implements LmtAdjustAppService, FrameworkService {
//    
//    private static Logger logger = LoggerFactory.getLogger(LmtAdjustAppServiceImpl.class);
//    
//    @Autowired
//    private LmtAdjustAppDao lmtAdjustAppDao;
//    @Autowired
//    private LmtIndivAppDao lmtIndivAppDao;
//    @Autowired
//    private LmtPrdContDao lmtPrdContDao;
//    @Autowired
//    private LmtShowInfoDao lmtShowInfoDao;
//    @Autowired
//    private LmtPrelistDao lmtPrelistDao;
//
//    @Autowired
//    @Qualifier("pubSysInfoService")
//    private PubSysInfoService pubSysInfoService;
//    @Autowired
//    @Qualifier("bizParamCfgService")
//    private BizParamCfgService bizParamCfgService;
//    @Autowired
//    @Qualifier("cusTaxBaseService")
//    private CusTaxBaseService cusTaxBaseService;
//    @Autowired
//    @Qualifier("ctrLoanContService")
//    private CtrLoanContService ctrLoanContService;
//    @Autowired
//    private LmtFreezeAppDao lmtFreezeAppDao;
//    @Autowired
//    private LmtTerminateAppDao lmtTerminateAppDao;
//    @SuppressWarnings("unchecked")
//	@Override
//    public List<LmtAdjustAppVO> queryAllOwner(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("查询本人所属的额度调整申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            List<LmtAdjustApp> dataList = lmtAdjustAppDao.queryAllOwnerByPage(inLmtAdjustAppVo);
//            if (Objects.nonNull(dataList)) {
//                List<LmtAdjustAppVO> resultList = new ArrayList<LmtAdjustAppVO>();
//                resultList = (List<LmtAdjustAppVO>) beansCopy(dataList, LmtAdjustAppVO.class);
//                pageSet(resultList, inLmtAdjustAppVo);
//                return resultList;
//            } else {
//                logger.info("查询本人所属的额度调整申请表记录为空！");
//            }
//        } catch (Exception e) {
//            logger.error("查询本人所属的额度调整申请表记录发生异常！", e);
//        }
//        return null;
//    }
//    
//    @SuppressWarnings("unchecked")
//	@Override
//    public List<LmtAdjustAppVO> queryAllCurrOrg(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("查询本机构的额度调整申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            List<LmtAdjustApp> dataList = lmtAdjustAppDao.queryAllCurrOrgByPage(inLmtAdjustAppVo);
//            if (Objects.nonNull(dataList)) {
//                List<LmtAdjustAppVO> resultList = new ArrayList<LmtAdjustAppVO>();
//                resultList = (List<LmtAdjustAppVO>) beansCopy(dataList, LmtAdjustAppVO.class);
//                pageSet(resultList, inLmtAdjustAppVo);
//                return resultList;
//            } else {
//                logger.info("查询本机构的额度调整申请表记录为空！");
//            }
//        } catch (Exception e) {
//            logger.error("查询本机构的额度调整申请表记录发生异常！", e);
//        }
//        return null;
//    }
//    
//    @SuppressWarnings("unchecked")
//	@Override
//    public List<LmtAdjustAppVO> queryAllCurrDownOrg(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("查询本机构及下属机构的额度调整申请表记录的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            List<LmtAdjustApp> dataList = lmtAdjustAppDao.queryAllCurrDownOrgByPage(inLmtAdjustAppVo);
//            if (Objects.nonNull(dataList)) {
//                List<LmtAdjustAppVO> resultList = new ArrayList<LmtAdjustAppVO>();
//                resultList = (List<LmtAdjustAppVO>) beansCopy(dataList, LmtAdjustAppVO.class);
//                pageSet(resultList, inLmtAdjustAppVo);
//                return resultList;
//            } else {
//                logger.info("查询本机构及下属机构的额度调整申请表记录为空！");
//            }
//        } catch (Exception e) {
//            logger.error("查询本机构及下属机构的额度调整申请表记录发生异常！", e);
//        }
//        return null;
//    }
//    
//    @Override
//    public int insertLmtAdjustApp(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("新增额度调整申请表数据的参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return 0;
//        }
//        int count = 0;
//        try {
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            beanCopy(inLmtAdjustAppVo, lmtAdjustApp);
//            count = lmtAdjustAppDao.insertLmtAdjustApp(lmtAdjustApp);
//        } catch (Exception e) {
//            logger.error("新增额度调整申请表数据发生异常！", e);
//            count = -1;
//        }
//        logger.info("当前新增额度调整申请表数据条数为：" + count);
//        return count;
//    }
//    
//    @Override
//    public int deleteLmtAdjustAppByPk(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("删除额度调整申请表数据的参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return 0;
//        }
//        int count = 0;
//        try {
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            beanCopy(inLmtAdjustAppVo, lmtAdjustApp);
//            count = lmtAdjustAppDao.deleteLmtAdjustAppByPk(lmtAdjustApp);
//        } catch (Exception e) {
//            logger.error("删除额度调整申请表数据发生异常！", e);
//            count = -1;
//        }
//        logger.info("删除的额度调整申请表数据条数为：" + count);
//        return count;
//    }
//    
//    @Override
//    public int updateLmtAdjustAppByPk(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("修改额度调整申请表数据的参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return 0;
//        }
//        int count = 0;
//        try {
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            beanCopy(inLmtAdjustAppVo, lmtAdjustApp);
//            count = lmtAdjustAppDao.updateLmtAdjustAppByPk(lmtAdjustApp);
//        } catch (Exception e) {
//            logger.error("修改数据发生异常！", e);
//            count = -1;
//        }
//        logger.info("修改的额度调整申请表数据条数为" + count);
//        return count;
//    }
//    
//    @Override
//    public LmtAdjustAppVO queryLmtAdjustAppByPk(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("根据主键查询额度调整申请表的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            beanCopy(inLmtAdjustAppVo, lmtAdjustApp);
//            lmtAdjustApp = lmtAdjustAppDao.queryLmtAdjustAppByPk(lmtAdjustApp);
//            if (Objects.nonNull(lmtAdjustApp)) {
//                LmtAdjustAppVO outLmtAdjustAppVo = beanCopy(lmtAdjustApp, new LmtAdjustAppVO());
//                return outLmtAdjustAppVo;
//            } else {
//                logger.info("根据主键查询额度调整申请表的记录为空！");
//            }
//        } catch (Exception e) {
//            logger.error("根据主键查询额度调整申请表记录发生异常！", e);
//        }
//        return null;
//    }
//    
//    @Override
//    public LmtAdjustAppVO querySingleLmtAdjustAppByCondition(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("根据条件查询单笔额度调整申请表的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            beanCopy(inLmtAdjustAppVo, lmtAdjustApp);
//            lmtAdjustApp = lmtAdjustAppDao.querySingleLmtAdjustAppByCondition(lmtAdjustApp);
//            if (Objects.nonNull(lmtAdjustApp)) {
//                LmtAdjustAppVO outLmtAdjustAppVo = beanCopy(lmtAdjustApp, new LmtAdjustAppVO());
//                return outLmtAdjustAppVo;
//            } else {
//                logger.info("根据条件查询单笔额度调整申请表的记录为空！");
//            }
//        } catch (Exception e) {
//            logger.error("根据条件查询单笔额度调整申请表记录发生异常！", e);
//        }
//        return null;
//    }
//    
//    @SuppressWarnings("unchecked")
//	@Override
//    public List<LmtAdjustAppVO> queryLmtAdjustAppByCondition(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("条件查询额度调整申请表的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            List<LmtAdjustApp> dataList = lmtAdjustAppDao.queryLmtAdjustAppByCondition(inLmtAdjustAppVo);
//            if (Objects.nonNull(dataList)) {
//                List<LmtAdjustAppVO> resultList = new ArrayList<LmtAdjustAppVO>();
//                resultList = (List<LmtAdjustAppVO>) beansCopy(dataList, LmtAdjustAppVO.class);
//                return resultList;
//            } else {
//                logger.info("条件查询额度调整申请表的数据为空！");
//            }
//        } catch (Exception e) {
//            logger.error("条件查询额度调整申请表发生异常！", e);
//        }
//        return null;
//    }
//    
//    @SuppressWarnings("unchecked")
//	@Override
//    public List<LmtAdjustAppVO> queryLmtAdjustAppByConditionByPage(LmtAdjustAppVO inLmtAdjustAppVo) {
//        logger.info("条件分页查询额度调整申请表的请求参数为：" + JSONObject.toJSONString(inLmtAdjustAppVo));
//        if(Objects.isNull(inLmtAdjustAppVo)){
//            return null;
//        }
//        try {
//            List<LmtAdjustApp> dataList = lmtAdjustAppDao.queryLmtAdjustAppByConditionByPage(inLmtAdjustAppVo);
//            if (Objects.nonNull(dataList)) {
//                List<LmtAdjustAppVO> resultList = new ArrayList<LmtAdjustAppVO>();
//                resultList = (List<LmtAdjustAppVO>) beansCopy(dataList, LmtAdjustAppVO.class);
//                return resultList;
//            } else {
//                logger.info("条件分页查询额度调整申请表的数据为空！");
//            }
//        } catch (Exception e) {
//            logger.error("条件分页查询额度调整申请表发生异常！", e);
//        }
//        return null;
//    }
//
////    @Override
////    public FlowOutSimpleVO insertLmtAdjustApp4Flow(String lmtSerno, String adjSerno, String adjBase) throws Exception {
////        logger.info("准入插入额度调整信息，adjSerno="+adjSerno);
////        FlowOutSimpleVO flowOutSimpleVO = new FlowOutSimpleVO();
////        
////        try {
////            // 获取营业日期
////            String openday = pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001);
////            logger.info("当前营业日期：" + openday);
////            
////            //获取授信申请
////            LmtIndivApp lmtIndivApp = new LmtIndivApp();
////            lmtIndivApp.setLmtSerno(lmtSerno);//授信申请流水号
////            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
////            BigDecimal lmtApplyAmt = BaseConstant.APPR_STATUS_997.equals(lmtIndivApp.getApproveStatus())?lmtIndivApp.getApproveAmt():BigDecimal.ZERO;
////            
////            //获取授信协议
////            LmtPrdContVO lmtPrdContVo = new LmtPrdContVO();
////            lmtPrdContVo.setLmtSerno(lmtSerno);//授信申请流水号
////            //有可能还没生成授信协议记录
////            List<LmtPrdCont> lmtPrdContList = lmtPrdContDao.queryLmtPrdList(lmtPrdContVo);
////            LmtPrdCont lmtPrdCont = Objects.nonNull(lmtPrdContList)&&lmtPrdContList.size()>0?lmtPrdContList.get(0):null;
////            String lmtContNo = Objects.nonNull(lmtPrdCont)?lmtPrdCont.getLmtContNo():"";
////            BigDecimal adjBasicLmt = Objects.nonNull(lmtPrdCont)?lmtPrdCont.getLmtAmt():lmtApplyAmt;
////            adjBasicLmt = Objects.isNull(adjBasicLmt)?BigDecimal.ZERO:adjBasicLmt;
////            
////            //查询最新的涉税授权流水号
////            logger.info("根据证件号码和法人机构号查询最新的涉税信息。certCode：" + lmtIndivApp.getCertCode() + "，legalOrgCode：" + lmtIndivApp.getLegalOrgCode());
////            CusTaxBaseVO taxBaseVO = cusTaxBaseService.queryLatestCusTaxBaseByCertCode(lmtIndivApp.getCertCode(), lmtIndivApp.getLegalOrgCode());
////            String outerAuthSerno = taxBaseVO.getAuthSerno();//涉税授权流水号
////            
////            //获取额度调整间隔天数
////            BizParamCfgVO bizParamCfgVO = bizParamCfgService.queryByLegalOrgCode(lmtIndivApp.getLegalOrgCode());
////            String freqDaysStr = bizParamCfgVO.getAmtIntervalCount();
////            int freqDays = 0;
////            try {
////                freqDays = Integer.parseInt(freqDaysStr);
////            } catch (Exception e) {
////                freqDays = 30;//如果配置为空，就默认30天
////            }
////            
////            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
////            lmtAdjustApp.setAdjSerno(adjSerno);//调整申请流水号
////            lmtAdjustApp.setLmtSerno(lmtSerno);//授信申请流水号
////            lmtAdjustApp.setLmtContNo(lmtContNo);//授信协议编号
////            //lmtAdjustApp.setContNo();//合同编号
////            lmtAdjustApp.setCusId(lmtIndivApp.getCusId());//客户号
////            lmtAdjustApp.setCusName(lmtIndivApp.getCusName());//客户名称
////            lmtAdjustApp.setCertType(lmtIndivApp.getCertType());//证件类型
////            lmtAdjustApp.setCertCode(lmtIndivApp.getCertCode());//证件号码
////            lmtAdjustApp.setAdjType(LimitConstant.ADJ_TYPE_INCREASE);//调整类型
////            lmtAdjustApp.setPrdId(lmtIndivApp.getPrdId());//产品ID
////            lmtAdjustApp.setPrdCode(lmtIndivApp.getPrdCode());//产品代码
////            lmtAdjustApp.setPrdName(lmtIndivApp.getPrdName());//产品名称
////            lmtAdjustApp.setApplyDate(openday);//申请日期
////            lmtAdjustApp.setAdjBasicLmt(adjBasicLmt);//调整基础额度
////            //lmtAdjustApp.setCalcLmt();//测算额度
////            lmtAdjustApp.setAdjResultLmt(BigDecimal.ZERO);//调整结果额度
////            lmtAdjustApp.setAdjBase(adjBase);//调整依据
////            lmtAdjustApp.setOuterAuthSerno(outerAuthSerno);//外部授权流水号
////            lmtAdjustApp.setAdjStatus(LimitConstant.ADJ_STATUS_00);//调整状态
////            lmtAdjustApp.setAdjComment("客户在手机银行发起提额申请。");//调整说明
////            lmtAdjustApp.setApproveStatus(BaseConstant.APPR_STATUS_111);//审批状态
////            //lmtAdjustApp.setFinalApprvDate();//最终审批日期
////            lmtAdjustApp.setActDeadline(TimeUtil.addDay(openday, freqDays));//激活截止日期
////            //lmtAdjustApp.setRejectReason();//拒绝调整原因
////            lmtAdjustApp.setCusManager(lmtIndivApp.getCusManager());//客户经理
////            lmtAdjustApp.setMainBrId(lmtIndivApp.getMainBrId());//主管机构
////            lmtAdjustApp.setLegalOrgCode(lmtIndivApp.getLegalOrgCode());//法人机构
////            lmtAdjustApp.setCreateUser(lmtIndivApp.getCusManager());//创建人
////            lmtAdjustApp.setCreateTime(TimeUtil.getCurrentDateTime());//创建时间
////            lmtAdjustApp.setLastUpdateUser(lmtIndivApp.getCusManager());//最后修改人
////            lmtAdjustApp.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
////            
////            logger.info("开始插入额度调整信息，lmtAdjustApp="+JSONObject.toJSONString(lmtAdjustApp));
////            lmtAdjustAppDao.insertLmtAdjustApp(lmtAdjustApp);
////            
////            //检查合同是否已签订
////            boolean signFlag = ctrLoanContService.getContSignedCountBySerno(lmtSerno) > 0;
////            logger.info("根据授信申请流水号["+lmtSerno+"]检查合同是否已签订，signFlag=" + signFlag);
////            
////            //修改lmt_show_info
////            LmtShowInfo lmtShowInfo = new LmtShowInfo();
////            lmtShowInfo.setLmtSerno(lmtSerno);
////            lmtShowInfo.setIncLmtInd(BaseConstant.NO);//提额过程中不允许提额
////            if(!signFlag) {
////                lmtShowInfo.setLmtStatus(PreCreStatus.MODIFY_DO.getCode());//提额中
////            }
////            lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());
////            lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
////            
////            flowOutSimpleVO.setBizSerno(adjSerno);//授信申请流水号
////            flowOutSimpleVO.setCusId(lmtAdjustApp.getCusId());//客户编号
////            flowOutSimpleVO.setCusName(lmtAdjustApp.getCusName());//客户名称
////            flowOutSimpleVO.setCertType(lmtAdjustApp.getCertType());//证件类型
////            flowOutSimpleVO.setCertCode(lmtAdjustApp.getCertCode());//证件号码
////            flowOutSimpleVO.setPrdId(lmtIndivApp.getPrdId());//产品ID
////            flowOutSimpleVO.setLegalOrgCode(lmtAdjustApp.getLegalOrgCode());//法人机构号
////        } catch (Exception e) {
////            logger.error("插入额度调整信息出现异常！", e);
////            throw new PauseException(e.getMessage());
////        } finally {
////            LmtShowInfo lmtShowInfo = new LmtShowInfo();
////            lmtShowInfo.setLmtSerno(lmtSerno);//授信申请流水号
////            lmtShowInfo.setIncLmtInd(BaseConstant.NO);//是否允许提额
////            lmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最新修改时间
////            lmtShowInfoDao.updateShowInfoByLmtSerno(lmtShowInfo);
////        }
////        
////        return flowOutSimpleVO;
////    }
//
//    @Override
//    public boolean lmtAdjustApprove(String adjSerno) throws Exception {
//        logger.info("额度调整审批。adjSerno=" + adjSerno);
//        try {
//            // 获取营业日期
//            String openday = pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001);
//            logger.info("当前营业日期：" + openday);
//            
//            //查询额度调整申请
//            LmtAdjustApp lmtAdjustApp = new LmtAdjustApp();
//            lmtAdjustApp.setAdjSerno(adjSerno);//额度调整申请流水号
//            LmtAdjustApp lmtAdjustAppFromDB = lmtAdjustAppDao.queryLmtAdjustAppByPk(lmtAdjustApp);
//            
//            //获取额度调整间隔天数
////            BizParamCfgVO bizParamCfgVO = bizParamCfgService.queryByLegalOrgCode(lmtAdjustAppFromDB.getLegalOrgCode());
//            String freqDaysStr = null; //bizParamCfgVO.getAmtIntervalCount();
//            int freqDays = 0;
//            try {
//                freqDays = Integer.parseInt(freqDaysStr);
//            } catch (Exception e) {
//                freqDays = 30;//如果配置为空，就默认30天
//            }
//            
//            lmtAdjustApp.setFinalApprvDate(openday);//审批日期
//            lmtAdjustApp.setActDeadline(TimeUtil.addDay(openday, freqDays));//激活截止日期
//            lmtAdjustApp.setApproveStatus(BaseConstant.APPR_STATUS_997);//审批通过
//            
//            //未提额通过的，提额结果为0
//            BigDecimal adjResultAmt = BaseConstant.APPR_STATUS_997.equals(lmtAdjustApp.getApproveStatus())?lmtAdjustAppFromDB.getAdjResultLmt():BigDecimal.ZERO;
//            if(adjResultAmt.intValue()==0) {
//                lmtAdjustApp.setAdjStatus(LimitConstant.ADJ_STATUS_99);
//                lmtAdjustApp.setRejectReason(LimitConstant.REJECT_REASON_03);
//            }
//            lmtAdjustApp.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
//            lmtAdjustAppDao.updateLmtAdjustAppByPk(lmtAdjustApp);
//            
//            //检查授信申请是否获得额度
//            String lmtSerno = lmtAdjustAppFromDB.getLmtSerno();
//            LmtIndivApp lmtIndivApp = new LmtIndivApp();
//            lmtIndivApp.setLmtSerno(lmtSerno);//授信申请流水号
//            lmtIndivApp = lmtIndivAppDao.queryByPk(lmtIndivApp);
//            boolean applySucc = BaseConstant.APPR_STATUS_997.equals(lmtIndivApp.getApproveStatus());
//            
//            //检查合同是否已签订
//            boolean signFlag = ctrLoanContService.getContSignedCountBySerno(lmtSerno) > 0;
//            logger.info("根据授信申请流水号["+lmtSerno+"]检查合同是否已签订，signFlag=" + signFlag);
//            
//            LmtPrelist lmtPrelist = lmtPrelistDao.queryLmtPrelistByLmtSerno(lmtAdjustAppFromDB.getLmtSerno());
//            LmtPrelist updateLmtPrelist = new LmtPrelist();
//            updateLmtPrelist.setLmtSerno(lmtSerno);//授信申请流水号
//            //修改lmt_show_info
//            LmtShowInfo lmtShowInfo = new LmtShowInfo();
//            lmtShowInfo.setLmtSerno(lmtAdjustAppFromDB.getLmtSerno());
//            lmtShowInfo = lmtShowInfoDao.querySingleLmtShowInfoByCondition(lmtShowInfo);
//            logger.info("额度调整通过前的lmtShowInfo:" + JSON.toJSONString(lmtShowInfo));
//            BigDecimal lmtAmt = lmtShowInfo.getLmtAmt();//授信总金额,应该取 LmtShowInfo 中的 lmtAmt
//            //申请没获得额度 且 没有签订过合同
//            if(!applySucc && !signFlag) {
//                logger.info("["+lmtSerno+"]授信申请未获得额度，且未存在已签订的合同！");
//                lmtAmt = BigDecimal.ZERO;
//            }
//            BigDecimal waitActAmt = lmtPrelist.getWaitActAmt();//授信总金额
////            updateLmtPrelist.setLmtAmt();//预授信总金额, 不应该修改
//            updateLmtPrelist.setWaitActAmt(waitActAmt.add(adjResultAmt));//待激活金额
//            if(signFlag) {
//                //已激活过额度
//                updateLmtPrelist.setCurOp(LimitConstant.PRELMT_OP_31);//提额完成
//            } else {
//                //未曾激活额度
//                updateLmtPrelist.setStatus(LimitConstant.PRELMT_STS_30);//待激活
//                updateLmtPrelist.setCurOp(LimitConstant.PRELMT_OP_31);//提额完成
//            }
//            updateLmtPrelist.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
//            logger.info("修改预授信名单额度！updateLmtPrelist=" + JSONObject.toJSONString(updateLmtPrelist));
//            lmtPrelistDao.updateByLmtSerno(updateLmtPrelist);
//
//            String lmtAdjSernos = lmtShowInfo.getLmtAdjSernos();//额度调整申请流水号
//            
//            LmtShowInfo updateLmtShowInfo = new LmtShowInfo();
//            updateLmtShowInfo.setLmtSerno(lmtAdjustAppFromDB.getLmtSerno());//授信申请流水号
//            updateLmtShowInfo.setLmtAmt(lmtAmt.add(adjResultAmt));//授信总金额
//            updateLmtShowInfo.setWaitActAmt(waitActAmt.add(adjResultAmt));//待激活金额
//            if(signFlag) {
//                //已激活过额度
//                updateLmtShowInfo.setLmtActType(LimitConstant.LMT_ACT_TYPE_2);//额度激活类型：提额额度激活
//            } else {
//                //未曾激活额度
//                //额度申请失败 且 本次提额得到额度为0
//                if(!applySucc && adjResultAmt.compareTo(BigDecimal.ZERO)==0) {
//                    updateLmtShowInfo.setLmtStatus(PreCreStatus.APPLY_FAIL.getCode());//申请失败
//                } else {
//                    updateLmtShowInfo.setLmtType(LimitConstant.PRELMT_TYPE_1);//申请得到额度，修改预授信额度类型：预授信额度
//                    updateLmtShowInfo.setLmtStatus(PreCreStatus.ACTIVE_WAIT.getCode());//待激活
//                    updateLmtShowInfo.setLmtActType(LimitConstant.LMT_ACT_TYPE_1);//额度激活类型：首次激活
//                }
//            }
//            if(StringUtil.isStrEmpty(lmtAdjSernos)) {
//                lmtAdjSernos = adjSerno;
//            } else {
//                lmtAdjSernos = lmtAdjSernos + "," + adjSerno;
//            }
//            updateLmtShowInfo.setLmtAdjSernos(lmtAdjSernos);
//            updateLmtShowInfo.setLastUpdateTime(TimeUtil.getCurrentDateTime());//最后修改时间
//            logger.info("修改lmt_show_info额度！lmtShowInfo=" + JSONObject.toJSONString(updateLmtShowInfo));
//            lmtShowInfoDao.updateShowInfoByLmtSerno(updateLmtShowInfo);
//        } catch (Exception e) {
//            logger.error("额度调整审批出现异常！", e);
//            throw new PauseException(e.getMessage());
//        }
//        return true;
//    }
//
//    @Override
//    public boolean queryPassAdjustApprove(String certCode) {
//        LmtAdjustAppVO lmtAdjustApp = new LmtAdjustAppVO();
//        lmtAdjustApp.setCertCode(certCode);
//        lmtAdjustApp.setApproveStatus(BaseConstant.APPR_STATUS_997);
//        int count = lmtAdjustAppDao.queryCountByCondition(lmtAdjustApp);
//        return count > 0;
//    }
//
//    @Override
//    public Map<String, String> checkIfAdjustCanActive(String lmtSerno) throws Exception {
//        logger.info("检查是否允许激活额度，lmtSerno=" + lmtSerno);
//        if(Objects.isNull(lmtSerno)) {
//            throw new Exception("授信申请流水号不能为空！");
//        }
//        Map<String, String> result = new HashMap<>();
//        //检查是否在激活中
//        LmtPrelist lmtPrelist = lmtPrelistDao.queryLmtPrelistByLmtSerno(lmtSerno);
//        if(LimitConstant.PRELMT_OP_20.equals(lmtPrelist.getCurOp())) {
//            result.put("flag", ESBConstant.FAILURE);
//            result.put("message", "额度正在激活中，请勿重复操作！");
//            return result;
//        }
//        
//        String flag = ESBConstant.SUCCESS;
//        String message = null;
//        
//        LmtPrdContVO lmtPrdCont = new LmtPrdContVO();
//        lmtPrdCont.setLmtSerno(lmtSerno);
//        List<LmtPrdCont> list = lmtPrdContDao.queryLmtPrdList(lmtPrdCont);
//        if(Objects.nonNull(list) && list.size()>0) {
//            LmtPrdCont prdCont = list.get(0);
//            String lmtContStatus = Objects.isNull(prdCont)?null:prdCont.getLmtStatus();
//            logger.info("授信协议["+lmtSerno+"]的状态为["+lmtContStatus+"]");
//            //非冻结或终止状态允许激活
//            if (LimitConstant.LMT_STATE_02.equals(lmtContStatus)){
//                flag = ESBConstant.FAILURE;
//                message = "存在额度被冻结，激活失败！";
//            }else if (LimitConstant.LMT_STATE_03.equals(lmtContStatus)){
//                flag = ESBConstant.FAILURE;
//                message = "存在额度已终止，激活失败！";
//            }else {
//
//                //存在冻结申请中记录，不允许激活
//                if(StringUtil.isStrNotEmpty(prdCont.getLmtContNo())) {
//                    int c = lmtFreezeAppDao.queryIfExistsFreezeProcessing(prdCont.getLmtContNo());
//                    logger.info("检查授信协议[" + prdCont.getLmtContNo() + "]是否存在审批中的冻结申请：" + (c>0));
//                    if (c > 0 ) {
//                        flag = ESBConstant.FAILURE;
//                        message = "存在冻结申请中记录，激活失败！";
//                    }else {
//                        //存在终止申请中记录，不允许激活
//                        LmtTerminateApp lmtTerminateApp = new LmtTerminateApp();
//                        lmtTerminateApp.setApproveStatus(BaseConstant.APPR_STATUS_111);
//                        lmtTerminateApp.setLmtContNo(prdCont.getLmtContNo());
//                        c = lmtTerminateAppDao.queryCountByCondition(lmtTerminateApp);
//                        logger.info("检查授信协议[" + prdCont.getLmtContNo() + "]是否存在审批中的额度终止申请：" + (c>0));
//                        if ( c > 0 ) {
//                            flag = ESBConstant.FAILURE;
//                            message = "存在冻结申请中记录，激活失败！";
//                        }
//                    }
//                }
//            }
//        } else {
//            throw new Exception("根据授信申请流水号["+lmtSerno+"]查询授信协议为空！");
//        }
//        result.put("flag", flag);
//        result.put("message", message);
//        return result;
//    }
//}